package com.qqt.csr.im.dto;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;
import com.qqt.csr.im.entity.Account;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 人工客服 im 账户信息
 * @author yang hao
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class MsgAccountDTO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
    * 主键
    */
    @Schema(description = "账号id")
    private String id;

    @Schema(description = "账户用户id")
    private String accountUserId;

    @Schema(description = "账户姓名")
    private String accountName;

    /**
     * 头像
     */
    @Schema(description="头像")
    private String headImg;

    /**
     * 是否在线
     */
    @Schema(description="是否在线")
    private Integer type;

    /**
     * 扩展 json格式
     */
    @Schema(description="扩展 json格式")
    private String artificialExt;

    public static MsgAccountDTO of(Account account){
        if(account == null){
            return null;
        }
        return MsgAccountDTO.builder()
                .id(account.getId().toString())
                .accountUserId(account.getAccountUserId())
                .accountName(account.getAccountName())
                .headImg(account.getHeadImg())
                .type(account.getType())
                .artificialExt(account.getExt())
                .build();
    }

    public static List<MsgAccountDTO> of(List<Account> accountList){
        if(CollectionUtils.isEmpty(accountList)){
            return Lists.newArrayList();
        }
        return accountList.stream().map(MsgAccountDTO::of).filter(Objects::nonNull).collect(Collectors.toList());
    }
}